package com.tsingteng.cosfun.ui.message.geneal.presenter;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;

import com.tsingteng.cosfun.bean.AttentFansbean;
import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.DataBean;
import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.NotificationBean;
import com.tsingteng.cosfun.bean.PlayBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.message.geneal.model.PlayModel;
import com.tsingteng.cosfun.utils.LogonUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 描述 :
 * 创建人: 肖利.
 * 时间:2018/8/6
 * qq(872179966)
 */

public class PlayPresenter extends BasePresenter<PlayContract.IPlayView> implements PlayContract.IPlayPresenter {

    private PlayContract.IPlayView mView;
    private PlayModel mModel;

    public PlayPresenter() {
        this.mModel = new PlayModel();
    }

    public PlayPresenter(PlayContract.IPlayView view) {
        this.mModel = new PlayModel();
        this.mView = view;
        attachView(mView);
    }

    @Override
    public void getPlayData(int pageNo, int pageSize) {
        if (mView == null) {
            mView = getView();
        }
        RxObserver<PlayBean> rxObserver = new RxObserver<PlayBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(PlayBean playBean) {
                mView.showPlayData(playBean);
            }
        };
        mModel.getPlayList(String.valueOf(pageNo), String.valueOf(pageSize), rxObserver);
        addDisposable(rxObserver);

    }

    @Override
    public void getPraiseOrNotData(String praise_type, String id, String type) {
        if (mView == null) {
            mView = getView();
        }
        RxObserver<Integer> rxObserver = new RxObserver<Integer>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(Integer data) {
                mView.showPraiseResult(data);
            }
        };
        mModel.getPraiseOrNot(praise_type, id, type, rxObserver);
        addDisposable(rxObserver);
    }


    //观看便当时长
    @Override
    public void getPlayLongTime(String start_time, String time_length) {
        if (null ==mView){
            mView =getView();
        }
        RxObserver<DataBean>  rxObserver=new RxObserver<DataBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
              mView.showTimeFail();
            }

            @Override
            protected void onSuccess(DataBean s) {
               mView.showLongTime(s);
            }
        };
        mModel.getDataLongTime(start_time,time_length,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void loginFollowFans(String follow_id) {
        if (mView == null) {
            mView = getView();
        }
        RxObserver<FollowBean> rxObserver = new RxObserver<FollowBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
            }

            @Override
            protected void onSuccess(FollowBean followBean) {
                mView.getFollowResult(followBean);
            }
        };

        mModel.getFollowNotification(follow_id, rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void loginNoFollow(String follow_id) {
        if (mView == null) {
            mView = getView();
        }
        RxObserver<FollowBean> rxObserver = new RxObserver<FollowBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                Log.e("ERROR", errorMsg);
            }

            @Override
            protected void onSuccess(FollowBean followBean) {
                mView.getFollowResult(followBean);
            }
        };

        mModel.getNoFollowNotification(follow_id, rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getDelPlay(String paragraph_id) {
        mView= getView();
        RxObserver<String> rxObserver = new RxObserver<String>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(String s) {
                mView.showDelResult(s);
            }
        };
        mModel.getDelPlay(paragraph_id,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getAddNotLikePlay(String paragraph_id) {
        mView= getView();
        RxObserver<String> rxObserver = new RxObserver<String>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(String s) {
                mView.ShowNotLiketResult(s);
            }
        };

        mModel.getAddNotLikePlay(paragraph_id,rxObserver);
        addDisposable(rxObserver);
    }
}
